//
//  ZGSDetaileFriendController.m
//  MapleLeaf
//
//  Created by 邝子涵 on 15/12/2.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "ZGSDetaileFriendController.h"

@interface ZGSDetaileFriendController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) ZGSDetaileModel *detaileSonModel;
@end

@implementation ZGSDetaileFriendController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self createView];
    
    [self createData];  // 数据解析
    
}

// 视图将要出现
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.961f green:0.325f blue:0.173f alpha:1.00f];
    self.title = @"动态详情";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName , nil]];
    
    self.tabBarController.tabBar.hidden = YES;
}



- (void)createView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    
    self.tableView.showsVerticalScrollIndicator = NO;
    
    
    // 注册
    [self.tableView registerClass:[ZGSmsgCommentListCell class] forCellReuseIdentifier:@"reuse"];
}

- (void)createData{
    [BaseAFN GETURLByString:[NSString stringWithFormat:@"http://api.youqudao.com/mhapi/api/feed/detail?customerId=1913463&mid=%@", self.mid] AFNData:^(id result) {
        NSDictionary *dic = result[@"data"];
        self.detaileSonModel = [[ZGSDetaileModel alloc] initWithDataSource:dic];
        
        if (dic.count > 0) {
            [self.tableView reloadData];
        }
        
    }];
}

#pragma mark tableView协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.detaileSonModel.msgCommentListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZGSmsgCommentListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    
    
    ZGSmsgCommentListModel *model = self.detaileSonModel.msgCommentListArray[indexPath.row];
    
    
    cell.msgModel = model;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}



#pragma mark - tableView头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    ZGSHearderView *hearderView = [[ZGSHearderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 210)];
    hearderView.model = self.detaileSonModel;
    
    return hearderView;
}

// 设置header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 220;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
